package com.cjl.auth.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjl.anno.OperLog;
import com.cjl.security.service.SysLoginLogService;
import com.cjl.commons.result.Result;
import com.cjl.model.system.SysLoginLog;
import com.cjl.vo.system.SysLoginLogQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 系统访问记录 前端控制器
 * </p>
 *
 * @author cjl
 * @since 2023-03-20
 */
@Api(tags = "登录日志管理接口")
@RestController
@RequestMapping("/admin/system/sysLoginLog")
public class SysLoginLogController {

    @Autowired
    private SysLoginLogService sysLoginLogService;

    @ApiOperation("日志条件分页查询")
    @GetMapping("{page}/{limit}")
    @OperLog(businessType = "LIST", title = "日志管理")
    public Result index(@PathVariable("page") Long page,
                        @PathVariable("limit") Long limit,
                        SysLoginLogQueryVo sysLoginLogQueryVo){
        Page<SysLoginLog> pageParam = new Page<>(page, limit);
        IPage<SysLoginLog> pageModel = sysLoginLogService.queryUser(sysLoginLogQueryVo, pageParam);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "获取登录日志")
    @GetMapping("get/{id}")
    @OperLog(businessType = "LIST", title = "日志管理")
    public Result get(@PathVariable Long id) {
        SysLoginLog loginLog = sysLoginLogService.getById(id);
        return Result.ok(loginLog);
    }
}

